package o;

import android.util.Log;
import androidx.annotation.NonNull;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class vv implements ry<InputStream> {
    private final ud ˊ;

    public /* synthetic */ boolean ˋ(@NonNull Object obj, @NonNull File file, @NonNull sc scVar) {
        return ˎ((InputStream) obj, file, scVar);
    }

    public vv(ud udVar) {
        this.ˊ = udVar;
    }

    public boolean ˎ(@NonNull InputStream inputStream, @NonNull File file, @NonNull sc scVar) {
        Throwable e;
        Throwable th;
        byte[] bArr = (byte[]) this.ˊ.ॱ(WXMediaMessage.THUMB_LENGTH_LIMIT, byte[].class);
        OutputStream fileOutputStream;
        try {
            fileOutputStream = new FileOutputStream(file);
            while (true) {
                try {
                    int read = inputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    fileOutputStream.write(bArr, 0, read);
                } catch (IOException e2) {
                    e = e2;
                }
            }
            fileOutputStream.close();
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e3) {
                }
            }
            this.ˊ.ˊ(bArr);
            return true;
        } catch (IOException e4) {
            e = e4;
            fileOutputStream = null;
            try {
                if (Log.isLoggable("StreamEncoder", 3)) {
                    Log.d("StreamEncoder", "Failed to encode data onto the OutputStream", e);
                }
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e5) {
                    }
                }
                this.ˊ.ˊ(bArr);
                return false;
            } catch (Throwable th2) {
                th = th2;
                if (fileOutputStream != null) {
                    try {
                        fileOutputStream.close();
                    } catch (IOException e6) {
                    }
                }
                this.ˊ.ˊ(bArr);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            fileOutputStream = null;
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
            this.ˊ.ˊ(bArr);
            throw th;
        }
    }
}
